#encoding:utf-8

import json
import os

class JudgeCore:
    workTitle = ''      #作业名称
    workSpace = ''      #工作区
    problems = []       #问题列表
    users = []          #待评列表
    result = {}         #评测结果
    userPathPrefix = 'src' #待评测文件目录（不含人名）
    dataPathPrefix = 'problem' #标准输出文件目录（不含类名）
    
    def __init__(self, jsonPath):
        os.chdir(jsonPath)
        self.workSpace = jsonPath
        str = ''
        self.users = os.listdir(self.userPathPrefix)
        with open('info.json', 'r') as conf:
            for i in conf.readlines():
                str += i
        jsonConf = json.loads(str)
        self.workTitle = jsonConf['workTitle']
        self.problems = jsonConf['problems']
        #print(self.problems)
        
    def judgeSingle(self, userIndex):
        path = "%s\\%s\\%s" % (self.workSpace, self.userPathPrefix, self.users[userIndex])
        className = self.problems[0]['className']
        for i in range(1, self.problems[0]['dataCount'] + 1):
            stdIn = "%s\\%s\\%s\\data\\%d.in" % (self.workSpace, self.dataPathPrefix, self.problems[0]['className'], i)
            stdOut = "%s\\%s\\%s\\data\\%d.out" % (self.workSpace, self.dataPathPrefix, self.problems[0]['className'], i)
            com = 'java -cp "%s" %s < "%s" 2>&1' % (path, className, stdIn)
            print(com)
        
if __name__ == '__main__':
    newjudge = JudgeCore(r'C:\Users\ospip\Desktop\170912JAVA')
    newjudge.judgeSingle(0)